<template>
  <router-view>
  </router-view>
</template>

<script>

import Header from "@/components/header/Header";
import Menu from "@/components/menu/Menu";
import Scan from "@/components/Scan";
import Sell from "@/components/sell/Sell";
import Input from "@/components/input/Input";
import Sms from "@/components/Sms";
import Cookies from 'js-cookie'
import store from "@/store";


export default {
  name: 'LAYOUT',
  components: {
    Sms,
    Scan,
    Header,
    Menu,
    Sell,
    Input,

  },
  data(){
    return{

    }
  },
  methods:{
    VerifyLogin(){
      if (Cookies.get('user')===undefined){
        store.commit("setCode",333)
        console.log(Cookies.get('user'))
        this.$router.push("/login")
      }
    }
  },

  mounted() {
    this.VerifyLogin()
  },

  created () {
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("blog-store") ) {
      this.$store.replaceState(Object.assign({}, this.$store.state,JSON.parse(sessionStorage.getItem("store"))))
      sessionStorage.removeItem("blog-store");
    }

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload",()=>{
      sessionStorage.setItem("blog-store",JSON.stringify(this.$store.state))
    })
  }



}



</script>

<style>

</style>
